// 声明函数指针数组实现不同的功能，函数为数组加和减。
#include<iostream>
using namespace std;
int * add(int *a,int *b,int n)
{
	int *c = new int(n);
	for(int i=0;i<n;i++)
	{
		c[i] = a[i]+b[i];
	}
	return c;
}
int * sub(int *a,int *b,int n)
{
	int *c = new int(n);
	for(int i=0;i<n;i++)
	{
		c[i] = a[i]-b[i];
	}
	return c;
}
void print(int *a,int n)
{
	for(int i=0;i<n;i++)
	{
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
int main()
{
	int a[] = {1,2,3};
	int b[] = {2,3,4};
	// 声明函数指针数组
	int *(*p1[2])(int *,int *,int n) = {add,sub};
	int *c = new int[3];
	int *d = new int[3];
	c = (*p1[0])(a,b,3);
	d = (*p1[1])(a,b,3);
	print(c,3);
	print(d,3);
	delete [] c;
	delete [] d;
}
